﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace Batman.Jianbei.Forum.Core.Datas
{
    public class ChatRoomDbFactory : IDesignTimeDbContextFactory<ChatRoomDbContext>
    {
        public ChatRoomDbContext CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json")
               .Build();

            var builder = new DbContextOptionsBuilder<ChatRoomDbContext>();
            var connectionString = configuration.GetConnectionString("Default");
            builder.UseMySql(connectionString);
            return new ChatRoomDbContext(builder.Options);
        }
    }
}
